<?php
require '../model/Db.php';
require '../model/Page.php';
$Db = Db::getInstance();
$admin_data = $Db->isadmin();
if(!$admin_data){
	$user_data = $Db->islogin();
	if($user_data['job'] == 3){
		$admin_data = $user_data;
	}
}
if(($admin_data || $user_data['job'] != 0) && is_numeric($_GET['id'])){
	$count =  $Db->count([
		table => ['report'],
		where => "cid = {$_GET['id']}"
	]);
	$page = page($count,30,5);
	$report_data = $Db->find([
		table => [content => 'a',report => 'b',bbs_user => 'c'],
		field => 'a.title,c.user,b.*',
		where => "a.id = b.cid and b.uid = c.id and b.cid = {$_GET['id']} order by b.cid,b.time desc {$page['limit']}"
	]);
	$report_data = $Db->tohtml($report_data);
	foreach($report_data as $item){
		$html .= <<<tr
				<tr>
					<td>{$item['cid']}</td>
					<td class="c-tt"><a target="_blank" href="/nsbbs/details.php?cid={$item['cid']}">{$item['title']}</a></td>
					<td><a target="_blank" href="/nsbbs/userinfo.php?uid={$item['uid']}">{$item['user']}</a></td>
					<td>{$item['reason']}</td>
					<td>{$item['time']}</td>
				</tr>
tr;
	}
	if(!$html){
		$html = '空空如也';
	}
	echo json_encode([html=>$html,page => $page['html']]);
}else{
	http_response_code(404);
	echo '<h1 style="color:#337ab7">千呼万唤始出来,犹抱琵琶半遮面</h1>';
}
